Skip to content

Don't reuse the connections.#39

Merged
kmike merged 1 commit intomainfrom
dont-reuse-connections
Nov 10, 2022
Merged

Don't reuse the connections.#39
kmike merged 1 commit intomainfrom
dont-reuse-connections

Conversation

@kmike
Copy link
Collaborator

@kmike kmike commented Nov 9, 2022

It seems aiohttp has troubles with edge cases of Keep-Alive (? not sure), and closing the TCP connection after each request helps with ServerDisconnectedErrors. I've been running multiple tests; ServerDisconnectedError can be reliably reproduced with current python-zyte-api, but I get none of them after this fix.

Using a single aiohttp session is still important, because it allows to reduce the number of ClientConnectorErrors.

It seems aiohttp has troubles with edge cases of Keep-Alive,
and disabling it helps with ServerDisconnectedErrors.

Using aiohttp sessions is still important, because it allows
to reduce the  number of ClientConnectorErrors.
@kmike kmike requested review from Gallaecio and ehilvanoz November 9, 2022 19:05
@codecov-commenter
Copy link

Codecov Report

Merging #39 (3591f41) into main (b2edeac) will not change coverage.
The diff coverage is 0.00%.

❗ Current head 3591f41 differs from pull request most recent head 58086f5. Consider uploading reports for the commit 58086f5 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #39   +/-   ##
=======================================
  Coverage   37.15%   37.15%           
=======================================
  Files           9        9           
  Lines         323      323           
  Branches       45       45           
=======================================
  Hits          120      120           
  Misses        203      203           
Impacted Files Coverage Δ
zyte_api/aio/client.py 27.39% <0.00%> (ø)

if "connector" not in kwargs:
kwargs["connector"] = TCPConnector(limit=connection_pool_size)
kwargs["connector"] = TCPConnector(limit=connection_pool_size,
force_close=True)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the reconnect overhead should not be a problem given the overall response time if the ping is good.
It might probably be in seconds for some percentile since it should (AFAIR) 3xRTT time.

Do we need a follow-up on that to try to optimise in in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it'd be nice to get to the root of it.
Probably it would make sense to focus on http2 support in the client though, not on http 1.1 keep-alive. It would require switching to a different http library.

@kmike kmike merged commit 4beeb8b into main Nov 10, 2022
@wRAR wRAR deleted the dont-reuse-connections branch April 5, 2025 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants